Skip to content

Additional testing#156

Merged
C-Achard merged 21 commits intomainfrom
cy/expand-testing
Feb 3, 2026
Merged

Additional testing#156
C-Achard merged 21 commits intomainfrom
cy/expand-testing

Conversation

@C-Achard
Copy link
Collaborator

@C-Achard C-Achard commented Jan 30, 2026

Expanded testing suite, addressing some missing coverage. Adds coverage reporting to the CI.

  • Focuses on core functionalities testing, and avoids redundancy with main DLC codebase (but pends further centralization)

    • Comprehensive tests for some core modules, including Assembler/Assembly
    • Introduces hypothesis-based testing to improve utility and robustness of tests
  • Minor fixes of some missing attributes.

  • Flags code duplication from main DLC codebase (may not be exhaustive yet)

  • Remove CI changes for now
    NOTE : Contains some CI/pre-commit changes, these can be removed before targeting main if we want them in a separate PR (but they will be used for formatting)


This pull request includes several improvements and updates across the codebase and CI configuration. The main themes are: adding pre-commit hooks for code quality, updating the test workflow and coverage reporting, and refactoring the dlclive/core/inferenceutils.py file for code clarity and modern Python standards.

Continuous Integration and Code Quality:

  • Added a .pre-commit-config.yaml file to configure pre-commit hooks for docstring checks, whitespace cleanup, setup.cfg formatting, and Ruff linter/formatter.
  • Updated the GitHub Actions workflow in .github/workflows/testing.yml to use newer action versions, streamline dependency installation, and add code coverage reporting with Codecov. [1] [2] [3]

Refactoring and Modernization of dlclive/core/inferenceutils.py:

  • Replaced deprecated or less strict built-in types and zip behavior with Python 3.10+ features (e.g., tuple[float, float] instead of Tuple[float, float], zip(..., strict=False) for safer iteration). [1] [2] [3] [4] [5] [6] [7]
  • Simplified and reformatted warning messages to use the stacklevel parameter for better tracebacks and improved readability of multi-line code blocks. [1] [2] [3]
  • Refactored several code blocks to use more compact and readable list comprehensions and function calls, reducing code duplication and improving maintainability. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Documentation and Comments:

  • Added a note at the top of dlclive/core/inferenceutils.py indicating that the file is a duplicate of the original DeepLabCut codebase, with author and date.

Introduces .pre-commit-config.yaml to automate code formatting, linting, and basic checks using pre-commit hooks for improved code quality and consistency.
Upgraded GitHub Actions to use newer versions and improved test steps by separating model benchmark and unit tests, adding coverage reporting with codecov. Added pytest-cov to dev dependencies and configured Ruff linter settings in pyproject.toml.
Introduces detailed unit tests for the Assembler, Assembly, Joint, and Link classes in dlclive.core.inferenceutils. The new tests cover metadata parsing, detection flattening, link extraction, assembly building, Mahalanobis distance calculation, I/O helpers, and various Assembly operations, improving test coverage and reliability.
Corrects color sampling in Display to avoid zero step and ensures image is always defined in display_frame. Adds comprehensive tests for Display, including headless environment setup, frame display, cutoff logic, window destruction, and color sampling safety.
Removed the --no-cache flag from 'uv sync' in the testing workflow, enhanced pytest coverage reporting, and added a step to summarize coverage in the GitHub Actions job summary. Added a note in dynamic_cropping.py about duplication with another file and referenced existing tests.
Introduces a new 'pose' attribute to the DLCLive class, initialized as None or a numpy ndarray. This prepares the class for storing pose data.
@C-Achard C-Achard self-assigned this Jan 30, 2026
@C-Achard C-Achard added enhancement New feature or request DLC 3.0 🔥 labels Jan 30, 2026
@C-Achard C-Achard marked this pull request as draft January 30, 2026 17:10
Copy link
Collaborator

@sneakers-the-rat sneakers-the-rat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it love it. We love tests. We love linting. I dont know too much about the code under test but gave a quick skim

Move test helpers into tests/conftest.py and introduce a suite of reusable pytest fixtures for assembler testing (headless_display_env, assembler graph/paf fixtures, scene factories, assembler/assembly/joint/link factories, and various canned dataset variants). Refactor tests/tests_core/test_assembler.py and tests/tests_core/test_assembly.py to consume the new fixtures, remove duplicated setup code, and simplify assertions. Also adjust serialization test filenames and tidy up identity/affinity-related test logic.
Replace handcrafted FakeTk/Label/PhotoImage classes with unittest.mock MagicMocks in the headless_display_env fixture. The fixture now returns a SimpleNamespace with mock constructors/instances (tk, label, photo) and sets display module attributes with monkeypatch (raising=False). Update tests to use the env mocks, assert on mock calls (title, pack, configure, update, destroy), mock ImageDraw.Draw with a MagicMock, and make colormap sampling deterministic for assertions. This simplifies test setup and enables precise call-based assertions instead of inspecting custom fake object state.
Replace tuple-based assembler fixtures with SimpleNamespace objects (providing .data, .graph, .paf_inds) and update all tests to access those attributes. Add Hypothesis to dev dependencies and introduce property-based tests for Assembly (from_array invariants and extent/area checks)
Introduce property-based tests for assembler utilities using Hypothesis: add test_condensed_index_properties for _conv_square_to_condensed_indices, a composite coords_and_conf strategy, test_flatten_detections_counts to validate _flatten_detections output counts, and a property test for extract_best_links (greedy) that asserts affinity, confidence-product (pcutoff) and disjointness invariants. Add Hypothesis imports, settings and numpy-array strategies. Also adjust test_assembly to ensure rows containing any NaN are set fully to NaN so the test matches Assembly.from_array behavior.
@C-Achard
Copy link
Collaborator Author

C-Achard commented Feb 2, 2026

Thanks again @sneakers-the-rat for the feedback, I've tried to integrate it best as I could. I also checked out other tools to help with robustness such as hypothesis, which I think integrates nicely here.
(Also I may have gone a bit overboard in the fixtures with SimpleNamespace, I like the dot access syntax but not sure if it's more readable as a result ?)

@C-Achard C-Achard marked this pull request as ready for review February 2, 2026 14:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the testing suite with comprehensive tests for core modules (Assembly, Assembler, Display) using Hypothesis for property-based testing, adds minor code quality improvements, and flags code duplication with the main DeepLabCut codebase.

Changes:

  • Comprehensive test coverage for Assembly and Assembler classes with hypothesis-based testing
  • New test fixtures in conftest.py for assembly/assembler testing scenarios
  • Code quality improvements: modernized type hints, simplified expressions, added stacklevel to warnings

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/tests_core/test_assembly.py Comprehensive tests for Assembly class with property-based testing
tests/tests_core/test_assembler.py Comprehensive tests for Assembler class with property-based testing
tests/test_display.py Tests for Display class using mocked tkinter
tests/conftest.py Test fixtures for assembly/assembler/display testing
tests/test_modelzoo.py Updated duplication comment format
tests/test_benchmark_script.py Added formatting and slow marker
pytest.ini Added slow test marker
pyproject.toml Added pytest-cov and hypothesis dependencies
dlclive/pose_estimation_pytorch/dynamic_cropping.py Simplified error messages, removed unused import
dlclive/modelzoo/utils.py Formatting improvements, updated duplication comments
dlclive/modelzoo/resolve_config.py Simplified error messages, updated duplication comments
dlclive/dlclive.py Minor formatting and added pose attribute
dlclive/display.py Fixed potential zero-step bug in color sampling
dlclive/core/inferenceutils.py Modernized type hints, added duplication note, minor refactoring
.pre-commit-config.yaml Added pre-commit hooks configuration
.github/workflows/testing.yml Updated test job names, commented out coverage reporting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@C-Achard C-Achard requested a review from Copilot February 3, 2026 08:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@deruyter92 deruyter92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR, thanks for adding so much test functionality! That's really needed.
I paid extra attention to the changes to display and the added testing. I left a comment about the clamping (and the testing thereof). For the rest, looks all good to me!

(and I like the use of hypothesis for testing, will look into it.)

Corrects swapped im_size indexing when clamping ellipse coordinates in Display.draw. The previous code used im_size[1] for x1 and im_size[0] for y1, which reversed width/height fallbacks and could produce incorrect bounds; x1 now uses im_size[0] (width) and y1 uses im_size[1] (height). This prevents drawing outside the image or using wrong coordinates.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@deruyter92 deruyter92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

Replace verbose conditional expressions with max/min to clamp pose-based ellipse coordinates (x0, x1, y0, y1) within image bounds.
@C-Achard C-Achard merged commit 45715db into main Feb 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DLC 3.0 🔥 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants